package weixinkeji.dev.dc.buy.order.h.fwy;

import java.util.List;
import sys.wx.ann.hm.M;
import sys.wx.ann.power.head.SQ;
import sys.wx.c.ATR;
import sys.wx.m.db.dao.mysql.Dao;
import weixinkeji.dev.dc.DCPower;
import weixinkeji.dev.dc.buy.order.bean.FWYOrder;
import weixinkeji.dev.dc.buy.order.bean.FWYOrderB;
import weixinkeji.dev.dc.buy.order.event.FWYEvent;
import weixinkeji.dev.dc.buy.order.event.FWYEventSO;
import weixinkeji.dev.dc.buy.order.so.FWYOrderSO;
import weixinkeji.dev.dc.buy.order.xy.FWYOrderXY;

@sys.wx.ann.hm.H("view/buy/order/fwy/kd/subimt")

//身份类型授权。无需人工付权。
//代表 是服务员才能进行访问。
@SQ(DCPower.ID_FWY)
public class FWYKDSubimtH {

    //查询未结账的单据。
    @M("/fwyorder")//通过 view/buy/order/fwy/kd/subimt/fwyorder.imy 访问
    public static String subimt(ATR a) {

        Object id = a.session.getAttribute(FWYOrderXY.H_MYSELECT_ORDER);
        if (null == id) {
            a.printOne("请先选择订单，然后再提交您的需求");
            return null;
        }
        FWYOrder fobj = Dao.selectOneByID(FWYOrder.class, id.toString());
        if (null == fobj.getOrder_id()) {
            a.printOne("选择的订单已被删除，无法完成提交操作！");
            return null;
        } else if (fobj.getOrder_sort().equals(FWYOrderXY.H_PAY_MONEY_ORDER)) {
            a.printOne("选择的订单已经结账，如需操作，请通知管理员打开此订单。订单号:" + fobj.getOrder_code());
            return null;
        }
        List<FWYOrderB> list = Dao.selectVast(FWYOrderB.class, "order_id='" + id + "' AND orderb_style=1");
        boolean x = FWYOrderSO.subimtOrder(id.toString());
        if (list.size() > 0 && x) {
            FWYEventSO.addEvent(new FWYEvent(fobj.getOrder_code(), fobj.getRoom_code(), "生效清单" + list.size()));
        } else if (list.size() > 0) {
            FWYEventSO.addEvent(new FWYEvent(fobj.getOrder_code(), fobj.getRoom_code(), "服务员提交订单失败，请关注"));
        }
        
        a.printOne(x ? "1" : "0");
        return null;
    }

}
